import { userAccountLogin } from '@/api/user'
// 用户状态
export default {
  namespaced: true,
  state: () => ({
    profile: {
      id: '',
      avatar: '',
      nickname: '',
      account: '',
      mobile: '',
      token: ''
    }
  }),
  mutations: {
    setUser (state, payload) {
      state.profile = payload
    },
    delUser (state) {
      state.profile = {}
    },
    delProfile (state) {
      state.profile = {}
    }
  },
  actions: {
    async asyncSetUser ({ commit }, formData) {
      const res = await userAccountLogin(formData)
      console.log('用户信息', res)
      commit('setUser', res)
    },
    // 退出登录
    async logoutAction ({ commit }) {
      commit('delProfile')
      commit('cart/setList', [], { root: true })
    }
  }
}
